<script type="text/javascript">
function deleteMembers(){
  	var count = jQuery('input.ckbChild:checked').length;
	if (count == 0){
		jQuery('#dialogDeleteOrg').html('<spring:message code="message.delete.empty.member"/>');
		jQuery('#dialogDeleteOrg').dialog({
	       	 modal:true,
	       	 resizable: false,
	         height:130,
          	 width:400,	
	       	 title:'<spring:message code="message"/>',
	       	 buttons:{
	       	 	'<spring:message code="button.cancel"/>' : function() {jQuery("#dialogDeleteOrg").dialog("close");}
	       	 }	
	 	});
    }else{
    jQuery('#dialogDeleteOrg').html('<spring:message code="message.confirm.delete.member"/>');
	jQuery('#dialogDeleteOrg').dialog({
       	 modal:true,
       	 resizable: false,
       	 height: 130,
       	 width:400,	
       	 title:'<spring:message code="message"/>',			         
         buttons: {
        	 '<spring:message code="button.ok"/>' : function() {
        		    jQuery('input[name=cmd]').val('deleteMembers');
           			document.frmMembers.submit();	 				 
           	},
           	'<spring:message code="button.cancel"/>' : function() {
	            jQuery('#dialogDeleteOrg').dialog("close");
	            jQuery('input[type="checkbox"]:checked').each(function(){
	    			this.checked = false;
	    	  	});	
	         }
          }
     });
	}
}

function addMembers(){
	var count = jQuery('input.ckbChild:checked').length;
	if (count == 0){
		jQuery('#dialogDeleteOrg').html('<spring:message code="message.add.empty.member"/>');
		jQuery('#dialogDeleteOrg').dialog({
	       	 modal:true,
	       	 resizable: false,
	         height:130,
          	 width:400,	
	       	 title:'<spring:message code="message"/>',
	       	 buttons:{
	       	 	'<spring:message code="button.cancel"/>' : function() {jQuery("#dialogDeleteOrg").dialog("close");}
	       	 }	
	 	});
    }else{
    jQuery('#dialogDeleteOrg').html('<spring:message code="message.confirm.add.member"/>');
	jQuery('#dialogDeleteOrg').dialog({
       	 modal:true,
       	 resizable: false,
       	 height: 130,
       	 width:400,	
       	 title:'<spring:message code="message"/>',			         
         buttons: {
        	 '<spring:message code="button.ok"/>' : function() {
        		    jQuery('input[name=cmd]').val('addMembers');
           			document.frmMembers.submit();	 				 
           	},
           	'<spring:message code="button.cancel"/>' : function() {
	            jQuery('#dialogDeleteOrg').dialog("close");	
	            jQuery('input[type="checkbox"]:checked').each(function(){
	    			this.checked = false;
	    	  	});	
	         }
          }
     });
    }
}

jQuery(document).ready(function(){
	
	jQuery("#addMembers").click(function(){
		addMembers();
	});
	
	jQuery("#deleteMembers").click(function(){
		deleteMembers();
	}); 
	
	jQuery("#searchMembers").click(function() {
		jQuery('input[name=cmd]').val('searchMembers');
		document.frmMembers.submit();
	 }); 
	
	jQuery("input.ckbSelectAll").click(function(){
        if(this.checked == true) {
            jQuery("input.ckbChild:not(:disabled)").attr("checked",true);
        } else {
            jQuery("input.ckbChild").attr("checked",false);
        }
    });
		
    jQuery("input.ckbChild").click(function(){
        if(this.checked == false) {
            jQuery("input.ckbSelectAll").attr("checked", false);
        }
        var count = jQuery('input.ckbChild:checked').length;
        var countList = jQuery('input[name="countList"]').val();	        
        if(countList == count){
            jQuery("input.ckbSelectAll").attr("checked", true);  
        }
    });
    
    var count = jQuery('input.ckbChild:checked').length;
    if(count == 0){
        jQuery("input.ckbSelectAll").attr("checked", false);  
    }	
});
</script>